package com.geek.javase.ch17.work.tcpwork.tcp6;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/*
 *@Date 2025/11/4
 *@Author wangpeng
 *@Description
 * * 自定义线程池类
 * 封装了 `ThreadPoolExecutor`，简化线程池的使用
 * 用于高效管理多个客户端连接的读取线程，避免频繁创建和销毁线程的开销
 */
public class ThreadPool {
    // 线程池执行器，实际负责线程的创建、管理和任务调度
    private ThreadPoolExecutor pool;

    public ThreadPool(int maxPoolSize, int queueSize) {
        pool = new ThreadPoolExecutor(
                2,maxPoolSize,
                60,TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(queueSize));
    }
    //执行方法，将任务提交给线程池执行
   public void execute(Runnable runnable) {
        pool.execute(runnable);
   }
}
